﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using CE.User;
using CE.Mail;

public partial class user_resend_user_activate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.Params["email"] != null)
        {
            if (Request.Params["email"].ToString().Length > 0)
            {
                string _srtEmail = Request.Params["email"].ToString();
                AccountStatus _accountstatus = new AccountStatus();
                AccountStatusDB _accountstatusdb = new AccountStatusDB();
                AccountDB _accountdb = new AccountDB();
                Account _account = _accountdb.GetUserAccount(_srtEmail);

                var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
                var random = new Random();
                var result = new string(Enumerable.Repeat(chars, 5).Select(s => s[random.Next(s.Length)]).ToArray());
                string salt = CE.Security.MySecurity.Encrypt(result, true);
                string strGUID = _accountdb.GetGUID(_account.UID);
                salt = salt.Replace("+", "");
                _account.AuthSalt = salt;
                if (_accountdb.Insert(_account) > 0)
                {
                    if (MyMailManager.SendNewUserActivateLink(_account.Email, _account.Email, _account.AuthSalt, strGUID, _account.AuthCode, CE.Global.CEUserType.Customer))
                    {
                        Response.Redirect("login.aspx?msg=resend");
                    }
                    else
                    {
                        //Response.Redirect("user-message.aspx?mt=UM&ec=1991");
                    }
                }
            }
        }
    }
}

